var num =0;
var timer;
var bgs=$(".lunbo #lunbo li")
var dots=$("#dot li");
//自动播放
// console.log(1)
function Autoplay(){
  timer= setInterval(function(){
		num++;
		num=num%$("#lunbo li").length;
     	bgs.eq(num).stop().fadeIn(500).siblings().fadeOut(1000);
		dots.eq(num).css("background","#FF7700").siblings().css("background","white");
	},3000)
}
Autoplay();
// //点击换图片
dots.click(function(){
	$(this).css("background","#FF7700").siblings().css("background","white");
    bgs.eq($(this).index()).stop().fadeIn(500).siblings().fadeOut(1000);
})

$(".btn_left .pre").eq(0).click(function(){
	num--;
	num = num%bgs.length;
	bgs.eq(num).stop().fadeIn(500).siblings().fadeOut(1000);
	dots.eq(num).css("background","#FF7700").siblings().css("background","white");
	
})

$(".btn_right .nex").eq(0).click(function(){
	num++;
	num = num%bgs.length;
	bgs.eq(num).stop().fadeIn(500).siblings().fadeOut(1000);
	dots.eq(num).css("background","#FF7700").siblings().css("background","white");	
})

$(".lunbo").mouseover(function(){
	clearInterval(timer);
})
$(".lunbo").mouseout(function(){
	timer=setInterval(function(){
		num++;
		num=num%$("#lunbo li").length;
     	bgs.eq(num).stop().fadeIn(500).siblings().fadeOut(1000);
		dots.eq(num).css("background","#FF7700").siblings().css("background","white");
	},3000)
})
//点击弹窗x  退出页面
$("#exit").click(function(){
	// console.log(1);
	 $(".bg").eq(0).css("display","none");
})

//克隆三个人物的肖像
	window.onload = function(){
		// console.log(1)
		$.ajax({
			type:"get",
			url:"json/sanren.json",
			async:false,
			success:function(response,status,xhr){
				// console.log(response);
			     for(var i =0;i<response.sanren.length;i++){
				$("<li></li>").html('<img src="'+response.sanren[i].address+'"><div class="info"><div class="left"><h3>'+response.sanren[i].title+'</h3><span>官网  |  礼包</span></div><div class="right"><div class="btn">进入新区</div><div class="btn">列表服务器</div></div></div>').appendTo($("#sanren"));
			}
			$(".body .content #sanren li").eq(0).remove();
			},
			error:function(){
				console.log("程序出错啦！");
			}
		})
		
		$.ajax({
		 type:"get",
		 url:"json/paihang.json",
		 async:false,
		 success:function(response,status,xhr){
		 	console.log(response);
		      for(var i =0;i<response.list.length;i++){
		 	$("<li></li>").html('<div class="left"><img src="'+response.list[i].address+'"></div><h4>'+response.list[i].name+'</h4> <span>'+response.list[i].time+'</span> <p>'+response.list[i].fu+'</p></li>').appendTo($("#paihang"));
		    $("#paihang li p:lt(3)").css("color","red");
		 }
		 $("#paihang li").eq(0).remove();
		 },
		 error:function(){
		 	console.log("程序出错啦！");
		 } 
		})
		
		$.ajax({
			type:"get",
			url:"json/tuijian.json",
			async:false,
			success:function(response,status,xhr)
			{
				// console.log("response");
				for(var i=0;i<response.jiu.length;i++){
					$("<li></li>").html('<img src="'+response.jiu[i].address+'" ><p>'+response.jiu[i].name+'</p><div class="box1">官网</div><div class="box2">开始游戏</div><div class="redu" style="background-position:'+response.jiu[i].tpad+'"></div>').appendTo($("#tuijian"));
				}
				$("#tuijian").children().eq(0).remove();
			},
			error:function(){
				console.log("程序出错");
			}
		})
		
		//其他游戏的渲染
		$.ajax({
			type:"get",
			url:"json/qita.json",
			async:false,
			success:function(response,status,xhr){
				for(var i =0 ;i<response.touxiang.length;i++){
					$("<li></li>").html('<img src="'+response.touxiang[i].address+'" ><p>'+response.touxiang[i].name+'</p>').appendTo($("#touxiang"));
				}
				$("#touxiang").children().eq(0).remove();
			},
		})
	}
	
	
	//js部分  当用登录时 
	var btn1 = document.getElementById("btn1");
	var btn2 = document.getElementById("btn2");
	btn1.onclick=function(){
		var xhr = new XMLHttpRequest();
		var url = "test.php?user="+$("#user").val()+"pass="+$("#pass").val();
		var method="post";
		xhr.open(method,url);
		xhr.send(null);
		xhr.onreadystatechange = function(){
			if(xhr.readyState==4){
				if(xhr.status==200){
					alert("您好！登录成功，欢迎回来");
					$(".denglu").eq(0).css("display","none");
					
				}
			}
		}
	}
	

